#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod=1e9+7;
int qpow(int x,int n)
{
    int ret=1;
    while(n)
    {
        if(n&1)ret=(ret*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return ret;
}

void solve()
{
    int n;
    cin>>n;
    vector<int>v(n+1),dp(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        dp[i]=(dp[i-1]+v[i])%mod;
    }
    int a=0,b=n*(n-1)/2%mod;
    for(int i=1;i<=n;i++)
    {
        a=(a+v[i]*((dp[n]-dp[i]+mod)%mod)%mod)%mod;
    }
    cout<<(a*qpow(b,mod-2))%mod<<endl;
}
signed main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    int T=1;
    cin>>T;
    while(T--)
    {
       solve();
    }
    return 0;
}